<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <beetl>include("/inc/head.html"){}</beetl>
    <title>任务列表</title>
    
    <script>
        function del(jobGroup, jobName) {
            swal({
                        title              : "您确定要删除当前任务？",
                        text               : "删除后无法恢复，请确认后删除！",
                        type               : "warning",
                        showCancelButton   : true,
                        confirmButtonColor : "#DD6B55",
                        confirmButtonText  : "删除",
                        cancelButtonText   : "保留",
                        closeOnConfirm     : false,
                        closeOnCancel      : false,
                        showLoaderOnConfirm: true
                    },
                    function (isConfirm) {
                        if (isConfirm) {
                            location.href = '${ctxPath}/quartz/delete?jobGroup={0}&jobName={1}'.replace('{0}', jobGroup).replace('{1}', jobName);
                            swal("提示", "删除成功！", "success");
                        } else {
                            swal("提示", "任务未被删除！", "info");
                        }
                    });
        }
        function pauseAll() {
            swal({
                        title              : "您确定要暂停所有任务？",
                        text               : "",
                        type               : "warning",
                        showCancelButton   : true,
                        closeOnConfirm     : false,
                        confirmButtonText  : "确定",
                        cancelButtonText   : "取消",
                        showLoaderOnConfirm: true
                    },
                    function () {
                        location.replace('${ctxPath}/quartz/pauseAll');
                    });
        }
        function resumeAll() {
            swal({
                        title              : "您确定要恢复所有任务？",
                        text               : "",
                        type               : "warning",
                        showCancelButton   : true,
                        closeOnConfirm     : false,
                        confirmButtonText  : "确定",
                        cancelButtonText   : "取消",
                        showLoaderOnConfirm: true
                    },
                    function () {
                        location.replace('${ctxPath}/quartz/resumeAll');
                    });
        }
        function pause(jobGroup, jobName) {
            swal({
                        title              : '暂停任务',
                        text               : "您确定要暂停{0}任务？".replace('{0}', jobName),
                        type               : "warning",
                        showCancelButton   : true,
                        closeOnConfirm     : false,
                        confirmButtonText  : "确定",
                        cancelButtonText   : "取消",
                        showLoaderOnConfirm: true
                    },
                    function () {
                        location.href = '${ctxPath}/quartz/pause?jobGroup={0}&jobName={1}'.replace('{0}', jobGroup).replace('{1}', jobName);
                    });
        }
        function resume(jobGroup, jobName) {
            swal({
                        title              : '恢复任务',
                        text               : "您确定要恢复{0}任务？".replace('{0}', jobName),
                        type               : "warning",
                        showCancelButton   : true,
                        closeOnConfirm     : false,
                        confirmButtonText  : "确定",
                        cancelButtonText   : "取消",
                        showLoaderOnConfirm: true
                    },
                    function () {
                        location.href = '${ctxPath}/quartz/resume?jobGroup={0}&jobName={1}'.replace('{0}', jobGroup).replace('{1}', jobName);
                    });
        }
        function trigger(jobGroup, jobName) {
            swal({
                        title              : '触发任务',
                        text               : "您确定要触发{0}任务？".replace('{0}', jobName),
                        type               : "warning",
                        showCancelButton   : true,
                        closeOnConfirm     : false,
                        confirmButtonText  : "确定",
                        cancelButtonText   : "取消",
                        showLoaderOnConfirm: true
                    },
                    function () {
                        location.href = '${ctxPath}/quartz/trigger?jobGroup={0}&jobName={1}'.replace('{0}', jobGroup).replace('{1}', jobName);
                    });
        }
        function updateCronExpression(triggerGroup, triggerName, cronExpression) {
            swal({
                        title            : "修改Cron表达式",
                        text             : "",
                        type             : "input",
                        showCancelButton : true,
                        closeOnConfirm   : false,
                        animation        : "slide-from-top",
                        confirmButtonText: "确定",
                        cancelButtonText : "取消",
                        inputPlaceholder : "请输入Cron表达式",
                        inputValue       : cronExpression
                    },
                    function (inputValue) {
                        if (inputValue === false) {
                            return false;
                        }
                        if (inputValue === '') {
                            swal.showInputError("必须输入Cron表达式");
                            return false;
                        }
                        swal("修改成功", "修改后表达式：" + inputValue, "success");
                        location.href = '${ctxPath}/quartz/updateCronExpression?triggerGroup={0}&triggerName={1}&cronExpression={2}'.replace('{0}', triggerGroup).replace('{1}', triggerName).replace('{2}', inputValue);
                    });
        }
    </script>
</head>
<body>
<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <!-- 屏幕缩小到一定范围，菜单隐藏，这个按钮会在右上角出现 -->
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false" aria-haspopup="true">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        
        <div class="navbar-header">
            <a class="navbar-brand" href="${ctxPath}/quartz/list">Quartz管理</a>
        </div>
        
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">批量操作 <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="javascript:void(0);" onclick="pauseAll();">暂停所有任务</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="javascript:void(0);" onclick="resumeAll();">恢复所有任务</a></li>
                    </ul>
                </li>
            </ul>
            
            <ul class="nav navbar-nav navbar-right">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Monitor <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="${ctxPath}/druid" target="_blank">Druid Monitor</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="${ctxPath}/monitoring" target="_blank">JavaMelody Monitor</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="table-responsive">
        <table data-toggle="table" data-show-columns="true">
            <thead>
            <tr>
                <th data-visible="false">序号</th>
                <th data-visible="false">任务组</th>
                <th>任务ID</th>
                <th data-visible="false">触发ID</th>
                <th data-visible="false">触发组</th>
                <th data-visible="false">任务开启时间</th>
                <th>下次触发时间</th>
                <th>上次触发时间</th>
                <th>Cron表达式</th>
                <th>状态</th>
                <th>正在执行主机</th>
                <th data-visible="false">调度名称</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <beetl>for(job in jobs){</beetl>
            <beetl>if(isNotEmpty(job.cronExpression)){</beetl>
            <tr>
                <td>${jobLP.index}</td>
                <td>${job.jobGroup}</td>
                <td>${job.jobName}</td>
                <td>${job.triggerName}</td>
                <td>${job.triggerGroup}</td>
                <td>${job.startTime}</td>
                <td>${job.nextFireTime}</td>
                <td>${job.previousFireTime}</td>
                <td>${job.cronExpression}</td>
                <td>${job.triggerState}</td>
                <td>${job.executionHost}</td>
                <td>${job.schedulerName}</td>
                <td>
                    <button type="button" class="btn btn-info" onclick="updateCronExpression('${job.triggerGroup}','${job.triggerName}','${job.cronExpression}');">修改Cron</button>
                    <button type="button" class="btn btn-warning" onclick="pause('${job.jobGroup}','${job.jobName}');">暂停任务</button>
                    <button type="button" class="btn btn-primary" onclick="resume('${job.jobGroup}','${job.jobName}');">恢复任务</button>
                    <button type="button" class="btn btn-success" onclick="trigger('${job.jobGroup}','${job.jobName}');">触发一次</button>
                    <button type="button" class="btn btn-danger" onclick="del('${job.jobGroup}','${job.jobName}');">删除任务</button>
                </td>
            </tr>
            <beetl>}</beetl>
            <beetl>}</beetl>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>